package co.fitstart.entity.courseware.fitnessgroup;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

/**
 * 
 * @author dan
 *
 */
@Entity
@Table(name = "daily_courseware_template")
@JsonIgnoreProperties(value={"hibernate_lazy_initializer","handler","fieldHandler"})
public class DailyCoursewareTemplate {
    
    @Id
    @GeneratedValue
    private Long id;
    
    /** 名称 */
    private String name;
    
    /** 顺序 */
    private int sorting;
    
    /** 类型 动作 or 休息日 */
    @Enumerated(EnumType.ORDINAL)
    private DailyCoursewareType type;
    
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    private BatchCoursewareTemplate batch;
    
    @Column(name = "is_disabled")
    private boolean disabled;
    
    /**
     * The default constructor
     */
    public DailyCoursewareTemplate() {
        
    }
    
    /**
     * 
     * @param name
     * @param sorting
     * @param batch
     */
    public DailyCoursewareTemplate(String name, int sorting, BatchCoursewareTemplate batch) {
        this.name = name;
        this.sorting = sorting;
        this.batch = batch;
        this.disabled = false;
    }
    
    public DailyCoursewareTemplate(DailyCoursewareTemplate daily, BatchCoursewareTemplate batch) {
        this.name = daily.getName();
        this.sorting = daily.getSorting();
        this.type = daily.getType();
        this.batch = batch;
        this.disabled = daily.isDisabled();
    }
    
    /**
     * 
     * @return
     */
    public DailyCoursewareTemplate changeType(DailyCoursewareType type) {
        this.type = type;
        return this;
    }
    
    /**
     * 
     * @return
     */
    public DailyCoursewareTemplate disable() {
        this.disabled = true;
        return this;
    }
    
    /**
     * 
     * @param template
     * @return
     */
    public DailyCoursewareTemplate edit(DailyCoursewareTemplate template) {
        this.type = template.getType();
        return this;
    }


	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getSorting() {
		return sorting;
	}

	public void setSorting(int sorting) {
		this.sorting = sorting;
	}

	public DailyCoursewareType getType() {
		return type;
	}

	public void setType(DailyCoursewareType type) {
		this.type = type;
	}

	public BatchCoursewareTemplate getBatch() {
		return batch;
	}

	public void setBatch(BatchCoursewareTemplate batch) {
		this.batch = batch;
	}

	public boolean isDisabled() {
		return disabled;
	}

	public void setDisabled(boolean disabled) {
		this.disabled = disabled;
	}
}
